<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>页面访问次数计数器(application计数器)</title>
    </head>
    <body>

    <!-- https://blog.csdn.net/wadhwaudw/article/details/102771242 -->

        <%
            int n;
            if(application.getAttribute("num") == null)
                n = 0;
            else
                n = Integer.valueOf(application.getAttribute("num").toString());
            if(session.isNew())
                n++;
            application.setAttribute("num", n);
            out.println("欢迎光临! 您是第 " + application.getAttribute("num") + " 位访问者！");
        %>
    </body>
</html>
